package com.taobao.action;

import com.taobao.pojo.Smaller;
import com.taobao.pojo.TBMessage;
import com.taobao.pojo.UserInfo;
import com.taobao.server.ConfigServer;
import com.taobao.server.UserInfoServer;
import com.taobao.tools.TBMessageDialog;
import com.taobao.ui.widget.SmallerWidget;
import com.taobao.ui.widget.UpdateSmallerWidget;

public class AddSmallerAction extends CommonAction {

    private ConfigServer configServer;
    private UserInfoServer userInfoServer;

    @Override
    public void doAction(Object uiObject) {
        final SmallerWidget smallerWidget = (SmallerWidget) uiObject;
        UpdateSmallerWidget updateSmallerWidget = smallerWidget.getUpdateSmallerWidget();

        final UserInfo userInfo = smallerWidget.getPojo(UserInfo.class);
        Smaller smaller = updateSmallerWidget.getPojo(Smaller.class);

        TBMessage message = userInfoServer.addSmaller(smaller);
        TBMessageDialog.messageHandler(smallerWidget.getShell(), message);

        if (message.getCode() == TBMessage.SUCCESS) {
            userInfo.getSmallers().add(smaller);
            smallerWidget.getDisplay().asyncExec(new Runnable() {
                public void run() {
                    smallerWidget.fillWidget(userInfo);
                }
            });
        }
    }

}
